//
//  BDMyClienteleViewController.m
//  iOS_beboy
//
//  Created by Chuz NetTech on 17/10/12.
//  Copyright © 2017年 com.8xiong. All rights reserved.
//

#import "BDMyClienteleViewController.h"
#import "BDGeneralCell.h"
#import "BDUserModel.h"
#import "BDMyClientele.h"
#import "BDPromotionViewController.h"
#import "BDLevelViewController.h"
#import "BDTixianViewController.h"

@interface BDMyClienteleViewController ()<UITableViewDelegate,UITableViewDataSource>{
    CGPoint centerPoint;
    CGFloat leftFloat;
    CGFloat rightFloat;
    CGFloat lineViewWidth;
    int currentSelect;
}
@property (nonatomic, strong) UIView *bgView;;
@property (nonatomic, strong) UIButton *customerButton;
@property (nonatomic, strong) UIButton *profitButton;
@property (nonatomic, strong) UIView *lineView;
@property (nonatomic, strong) NSDictionary *datasource;


@property (nonatomic, strong) CAShapeLayer *shapeLayer;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *datasourceArray;
@property (nonatomic, strong) NSMutableArray *rightDataArray;
@property (nonatomic, strong) UIView *leftView;
@property (nonatomic, strong) UIView *rightView;
@property (nonatomic, strong) UILabel *detailsLabel;

@property (nonatomic, strong) UILabel *numberLabel;

@property (nonatomic, copy) void(^returnBlock)(NSDictionary *dict);
@property (nonatomic, copy) void(^returnProfit)(NSDictionary *dict);
@property (nonatomic, copy) void(^retunrnRightData)();

@property (nonatomic, strong) NSArray *levelStringArray;

@end

@implementation BDMyClienteleViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    currentSelect = 1;
    self.levelStringArray = @[@"s",@"m",@"l"];
    UIView *customerView = [[UIView alloc] init];
    customerView.height = 44;
    
    self.customerButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _customerButton.left = 0;
    [_customerButton setTitle:ASLocalizedString(@"我的客户")forState:UIControlStateNormal];
    _customerButton.titleLabel.font = [UIFont systemFontOfSize:16];
    [_customerButton sizeToFit];
    [_customerButton addTarget:self action:@selector(customerAction) forControlEvents:UIControlEventTouchUpInside];
    _customerButton.centerY = customerView.height / 2;
    [customerView addSubview:_customerButton];
    
    self.profitButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _profitButton.left = _customerButton.right + 20;
    [_profitButton setTitle:ASLocalizedString(@"我的利润")forState:UIControlStateNormal];
    _profitButton.titleLabel.font = [UIFont systemFontOfSize:16];
    [_profitButton setTitleColor:kNOValidColor forState:UIControlStateNormal];
    [_profitButton sizeToFit];
    [_profitButton addTarget:self action:@selector(profitAction) forControlEvents:UIControlEventTouchUpInside];
    _profitButton.centerY = customerView.height / 2;
    [customerView addSubview:_profitButton];
    
    customerView.width = _customerButton.width + _profitButton.width + 20;
    lineViewWidth = customerView.width;
    self.navigationItem.titleView = customerView;
    
    
    
    UIButton *promotionButton = [UIButton buttonWithType:UIButtonTypeCustom];
    promotionButton.frame = CGRectMake(0, 0, 60, 40);
    [promotionButton setTitle:ASLocalizedString(@"推广")forState:UIControlStateNormal];
    [promotionButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    promotionButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [promotionButton addTarget:self action:@selector(promotionAction) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *recordButton = [[UIBarButtonItem alloc] initWithCustomView:promotionButton];
    self.navigationItem.rightBarButtonItem = recordButton;
    
    
    [self createUI];
    
    [self createRightUI];
    
    _datasourceArray = [NSMutableArray array];
    _rightDataArray = [NSMutableArray array];
    
    [self requestData];
    
    [self requestDataProfit];
    
}

-(void)requestData{
    
    NSString *url = [NSString stringWithFormat:@"%@MLMRelates",KBDBaseURL];
    
    NSString *headValid = [BDUserModel getHeaderValidation];
    RACSignal *signal = [[BDNetworkingServer yy_GET:url parameters:nil validation:headValid automaticProcessingError:YES] execute:nil];
    [signal subscribeNext:^(id  _Nullable x) {
        self.returnBlock(x);
        self.datasource = [NSDictionary dictionaryWithDictionary:x];
        
        [_datasourceArray addObject:[BDGeneralModel new].titleEqual(ASLocalizedString(@"一级\n客户")).subTitleEqual([NSString stringWithFormat:@"%@",self.datasource[@"s_children"]]).laberStringEqual([NSString stringWithFormat:@"%@",self.datasource[@"new_s_children"]]).imageEqual(ASLocalizedString(@"一级")).accessoryTypeTypeEqual(BDGeneralCellAccessoryTypeDisclosureIndicator).modeEqual(BDGeneralCellModeLabel | BDGeneralCellModeCustomView)];
        
        [_datasourceArray addObject:[BDGeneralModel new].titleEqual(ASLocalizedString(@"二级\n客户")).subTitleEqual([NSString stringWithFormat:@"%@",self.datasource[@"m_children"]]).laberStringEqual([NSString stringWithFormat:@"%@",self.datasource[@"new_m_children"]]).imageEqual(ASLocalizedString(@"二级")).accessoryTypeTypeEqual(BDGeneralCellAccessoryTypeDisclosureIndicator).modeEqual(BDGeneralCellModeLabel | BDGeneralCellModeCustomView)];
        
        [_datasourceArray addObject:[BDGeneralModel new].titleEqual(ASLocalizedString(@"三级\n客户")).subTitleEqual([NSString stringWithFormat:@"%@",self.datasource[@"l_children"]]).laberStringEqual([NSString stringWithFormat:@"%@",self.datasource[@"new_l_children"]]).imageEqual(ASLocalizedString(@"三级")).accessoryTypeTypeEqual(BDGeneralCellAccessoryTypeDisclosureIndicator).modeEqual(BDGeneralCellModeLabel | BDGeneralCellModeCustomView)];
        
        [self.tableView reloadData];
    }];
    
    [signal subscribeError:^(NSError * _Nullable error) {
        // BDLog(ASLocalizedString(@"请求错误原因：%@"), @(error.code));
    }];
}

-(void)requestDataProfit{
    
    NSString *url = [NSString stringWithFormat:@"%@MLMProfit",KBDBaseURL];
    
    NSString *headValid = [BDUserModel getHeaderValidation];
    RACSignal *signal = [[BDNetworkingServer yy_GET:url parameters:nil validation:headValid automaticProcessingError:YES] execute:nil];
    
    [signal subscribeNext:^(id  _Nullable x) {
        
        self.returnProfit(x);
        
        self.datasource = [NSDictionary dictionaryWithDictionary:x];
        
        NSArray <BDMyClientele *> *clienteleArray = [BDMyClientele mj_objectArrayWithKeyValuesArray:self.datasource[@"logs"][@"list"]];
        
        for (int i = 0; i < clienteleArray.count; i++) {
            NSDate *date = [NSDate dateWithTimeIntervalSince1970:[clienteleArray[i].created_at integerValue]];
            NSString *st = [NSString stringWithFormat:ASLocalizedString(@"%zd月%zd日 %zd: %zd"), date.month, date.day, date.hour, date.minute];
            
            [_rightDataArray addObject:[BDGeneralModel new].titleEqual(clienteleArray[i].from[@"nickname"]).subTitleEqual([NSString stringWithFormat:@"%@",st]).laberStringEqual([NSString stringWithFormat:@"+%@",clienteleArray[i].balance]).imageEqual(clienteleArray[i].from[@"cover"]).placeImageEqual(@"avatar").imageTypeEqual(BDGeneralCellImageTypeURL).modeEqual(BDGeneralCellModeLabel | BDGeneralCellModeRightImage)];
            
        }
        
    }];
}

-(void)promotionAction{
//    NSLog(ASLocalizedString(@"推广"));
    BDPromotionViewController *promotionVC = [[BDPromotionViewController alloc] init];
    [self.navigationController pushViewController:promotionVC animated:YES];
}

-(void)createUI{
    
    self.bgView = [[UIView alloc] init];
    _bgView.backgroundColor = [UIColor whiteColor];
    _bgView.top = 64;
    _bgView.left = 0;
    _bgView.width = kBDScreenWidth;
    
    [self.view addSubview:_bgView];

    self.lineView = [[UIView alloc] init];
    _lineView.left = (kBDScreenWidth - lineViewWidth) / 2;
    _lineView.top = 64;
    _lineView.size = CGSizeMake(_customerButton.width, 2);
    _lineView.backgroundColor = KBDColorBlue;
    [self.view addSubview:self.lineView];
    
    self.leftView = [[UIView alloc] init];
    self.leftView.backgroundColor = [UIColor clearColor];
    self.leftView.top = 64;
    self.leftView.left = 0;
    self.leftView.width = kBDScreenWidth;
    [self.view addSubview:self.leftView];
    
    
    self.shapeLayer = [CAShapeLayer layer];
    
    [self.shapeLayer setFillColor:[UIColor clearColor].CGColor];
    
    [self.shapeLayer setStrokeColor:KBDColorBlue.CGColor];
    
    [self.shapeLayer setLineWidth:2];
    
    [self.shapeLayer setLineJoin:kCALineJoinRound];
    
    [self.shapeLayer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:2],
                                         [NSNumber numberWithInt:2],nil]];
    
    centerPoint = CGPointMake(kBDScreenWidth / 2, 20 + 100);
    
    CGFloat radiud = 100;
    
    UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:centerPoint radius:radiud startAngle:M_PI_2 * 4 / 3 endAngle:M_PI_2 * 2 / 3 clockwise:YES];
    
    
    self.shapeLayer.path = path.CGPath;
    
    [_bgView.layer addSublayer:self.shapeLayer];
    
    CGFloat startRadius = 95;
    CGFloat endRadius = startRadius - 10;
    
    for (int i = 0; i < 11; i++) {
        CGFloat angel = M_PI_2 * 2 / 3 - M_PI_2 / 3 * i;
        CGFloat startX = centerPoint.x + cos(angel) * startRadius;
        CGFloat startY = centerPoint.y + sin(angel) * startRadius;
        CGFloat endX = centerPoint.x + cos(angel) * endRadius;
        CGFloat endY = centerPoint.y + sin(angel) * endRadius;
        
        UIBezierPath *bezierPath = [UIBezierPath bezierPath];
        [bezierPath moveToPoint:CGPointMake(startX, startY)];
        [bezierPath addLineToPoint:CGPointMake(endX, endY)];
        
        CAShapeLayer *pointerLayer = [CAShapeLayer layer];
        [pointerLayer setLineWidth:3];
        [pointerLayer setStrokeColor:KBDColorBlue.CGColor];
        pointerLayer.path = bezierPath.CGPath;
        [_bgView.layer addSublayer:pointerLayer];
    }
    
    self.numberLabel = [[UILabel alloc] init];
    _numberLabel.font = [UIFont systemFontOfSize:36];
    _numberLabel.textColor = KBDColorBlue;
    [self.leftView addSubview:_numberLabel];
    
    
    UILabel *introduceLabel = [[UILabel alloc] init];
    introduceLabel.text = ASLocalizedString(@"累计客户数");
    introduceLabel.textColor = [UIColor colorWithHexString:@"4c4c4c"];
    introduceLabel.font = [UIFont systemFontOfSize:14];
    [introduceLabel sizeToFit];
    [self.leftView addSubview:introduceLabel];
    
    
    UILabel *unitLabel = [[UILabel alloc] init];
    unitLabel.text = ASLocalizedString(@"单位：个");
    unitLabel.textColor = [UIColor colorWithHexString:@"767676"];
    unitLabel.font = [UIFont systemFontOfSize:14];
    [unitLabel sizeToFit];
    [self.leftView addSubview:unitLabel];
    
    
    UILabel *todayNumberLabel = [[UILabel alloc] init];
    todayNumberLabel.font = [UIFont systemFontOfSize:14];
    todayNumberLabel.textColor = [UIColor colorWithHexString:@"4c4c4c"];
    todayNumberLabel.textAlignment = NSTextAlignmentCenter;
    [self.leftView addSubview:todayNumberLabel];
    
    self.detailsLabel = [[UILabel alloc] init];
    _detailsLabel.text = ASLocalizedString(@"客户明细");
    _detailsLabel.font = [UIFont systemFontOfSize:12];
    _detailsLabel.textColor = [UIColor colorWithHexString:@"4c4c4c"];
    _detailsLabel.left = 15;
    [_detailsLabel sizeToFit];
    [self.view addSubview:_detailsLabel];
    
    self.tableView = [[UITableView alloc] init];
    self.tableView.left = 0;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.width = kBDScreenWidth;
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.tableFooterView = [[UIView alloc] init];
    self.tableView.scrollEnabled = NO;
    [self.view addSubview:self.tableView];
    
    __block NSString *string;
    __block NSRange range;
    __block NSMutableAttributedString *todayString;
    __block CAShapeLayer *borderLayer;
    
    __weak typeof(self) weakSelf = self;
    self.returnBlock = ^(NSDictionary *dict){
        
        weakSelf.numberLabel.text = [NSString stringWithFormat:@"%@",dict[@"total_children"]];
        [weakSelf.numberLabel sizeToFit];
        weakSelf.numberLabel.top = centerPoint.y - _numberLabel.height;
        weakSelf.numberLabel.left = centerPoint.x - (_numberLabel.width / 2);
        
        introduceLabel.top = weakSelf.numberLabel.bottom + 13;
        introduceLabel.centerX = weakSelf.numberLabel.centerX;
        
        unitLabel.top = introduceLabel.bottom + 56;
        unitLabel.centerX = introduceLabel.centerX;
        
        todayNumberLabel.top = unitLabel.bottom + 15;
        
        string = [NSString stringWithFormat:ASLocalizedString(@"今日累计新增 %@ 客户"),dict[@"new_children"]];
        range = [string rangeOfString:[NSString stringWithFormat:@"%@",dict[@"new_children"]]];
        
        todayString = [[NSMutableAttributedString alloc] initWithString:string];
        [todayString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"ff0025"] range:range];
        [todayString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:range];
        
        todayNumberLabel.attributedText = todayString;
        [todayNumberLabel sizeToFit];
        todayNumberLabel.width += 20;
        todayNumberLabel.height += 20;
        todayNumberLabel.centerX = unitLabel.centerX;
        
        todayNumberLabel.layer.cornerRadius = todayNumberLabel.height / 2;
        
        borderLayer = [CAShapeLayer layer];
        borderLayer.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, todayNumberLabel.width, todayNumberLabel.height) cornerRadius:todayNumberLabel.height / 2].CGPath;
        borderLayer.lineWidth = 1;
        borderLayer.lineDashPattern = @[@4,@2];
        borderLayer.fillColor = [UIColor clearColor].CGColor;
        borderLayer.strokeColor = [UIColor colorWithHexString:@"cccccc"].CGColor;
        [todayNumberLabel.layer addSublayer:borderLayer];
        
        leftFloat = todayNumberLabel.bottom + 17;
        weakSelf.bgView.height = leftFloat;
        
        weakSelf.leftView.height = weakSelf.bgView.height;
        
        weakSelf.detailsLabel.top = weakSelf.bgView.bottom + 18 / 2;
        
        weakSelf.tableView.top = weakSelf.detailsLabel.bottom + 9;
        
        weakSelf.tableView.height = kBDScreenHeight - weakSelf.tableView.top;
    };
}

-(void)createRightUI{
    self.rightView = [[UIView alloc] init];
    self.rightView.backgroundColor = [UIColor clearColor];
    self.rightView.top = 64;
    self.rightView.left = 0;
    self.rightView.width = kBDScreenWidth;
    self.rightView.hidden = YES;
    [self.view addSubview:self.rightView];

    UILabel *addLabel = [[UILabel alloc] init];
    addLabel.top = 50;
    addLabel.textColor = [UIColor colorWithHexString:@"ff0025"];
    addLabel.font = [UIFont systemFontOfSize:28];
    [self.rightView addSubview:addLabel];
    
    UILabel *marginLabel = [[UILabel alloc] init];
    marginLabel.text = ASLocalizedString(@"今日新增利润");
    marginLabel.textColor = [UIColor colorWithHexString:@"4c4c4c"];
    marginLabel.font = [UIFont systemFontOfSize:14];
    [marginLabel sizeToFit];
    [self.rightView addSubview:marginLabel];
    
    
    UILabel *withdrawLabel = [[UILabel alloc] init];
    withdrawLabel.textColor = KBDColorBlue;
    withdrawLabel.font = [UIFont systemFontOfSize:28];
    [self.rightView addSubview:withdrawLabel];
    
    UILabel *cashProfitLabel = [[UILabel alloc] init];
    cashProfitLabel.text = ASLocalizedString(@"可提现利润");
    cashProfitLabel.font = [UIFont systemFontOfSize:14];
    cashProfitLabel.textColor = [UIColor colorWithHexString:@"4c4c4c"];
    [cashProfitLabel sizeToFit];
    [self.rightView addSubview:cashProfitLabel];
    
    UILabel *unitLabel = [[UILabel alloc] init];
    unitLabel.text = ASLocalizedString(@"单位：个");
    unitLabel.textColor = [UIColor colorWithHexString:@"767676"];
    unitLabel.font = [UIFont systemFontOfSize:14];
    [unitLabel sizeToFit];
    [self.rightView addSubview:unitLabel];
    
    UIButton *cashProfitButton = [UIButton buttonWithType:UIButtonTypeCustom];
    cashProfitButton.size = CGSizeMake(200, 46);
    [cashProfitButton setTitle:ASLocalizedString(@"利润提现")forState:UIControlStateNormal];
    cashProfitButton.titleLabel.font = [UIFont systemFontOfSize:17];
    cashProfitButton.titleLabel.textColor = [UIColor whiteColor];
    cashProfitButton.backgroundColor = KBDColorBlue;
    cashProfitButton.layer.cornerRadius = 5;
    [self.rightView addSubview:cashProfitButton];

    
    UILabel *accountLabel = [[UILabel alloc] init];
    accountLabel.font = [UIFont systemFontOfSize:14];
    accountLabel.textColor = [UIColor colorWithHexString:@"4c4c4c"];
    [self.rightView addSubview:accountLabel];
    
    
    __weak typeof(self) weakself = self;
    self.returnProfit = ^(NSDictionary *dic){
        addLabel.text = [NSString stringWithFormat:@"%@",dic[@"today_balance"]];
        [addLabel sizeToFit];
        addLabel.centerX = weakself.rightView.centerX;
        
        marginLabel.top = addLabel.bottom + 10;
        marginLabel.centerX = addLabel.centerX;
        
        withdrawLabel.top = marginLabel.bottom + 20;
        withdrawLabel.text = [NSString stringWithFormat:@"%@",dic[@"remain_balance"]];
        [withdrawLabel sizeToFit];
        withdrawLabel.centerX = marginLabel.centerX;
        
        cashProfitLabel.top = withdrawLabel.bottom + 10;
        cashProfitLabel.centerX = withdrawLabel.centerX;
        
        unitLabel.top = cashProfitLabel.bottom + 15;
        unitLabel.centerX = cashProfitLabel.centerX;
        
        cashProfitButton.top = unitLabel.bottom + 17;
        cashProfitButton.centerX = unitLabel.centerX;
        
        accountLabel.top = cashProfitButton.bottom + 17;
        
        NSString *accountString = [NSString stringWithFormat:ASLocalizedString(@"账户累计利润 %@元"),dic[@"total_balance"]];
        NSRange range = [accountString rangeOfString:[NSString stringWithFormat:@"%@",dic[@"total_balance"]]];
        
        NSMutableAttributedString *accountAttString = [[NSMutableAttributedString alloc] initWithString:accountString];
        [accountAttString addAttribute:NSForegroundColorAttributeName value:KBDColorBlue range:range];
        accountLabel.attributedText = accountAttString;
        [accountLabel sizeToFit];
        accountLabel.centerX = unitLabel.centerX;
        
        rightFloat = accountLabel.bottom + 17;
        
        
        [[cashProfitButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            BDTixianViewController *tixianVC = [[BDTixianViewController alloc] init];
            tixianVC.dict = dic;
            tixianVC.type = @"2";
            [weakself.navigationController pushViewController:tixianVC animated:YES];
        }];
    };
    
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (currentSelect == 1) {
        return _datasourceArray.count;
    }else{
        return _rightDataArray.count;
    }
    
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    BDGeneralModel *model;
    
    NSString *identifierString = nil;
    
    if (currentSelect == 1) {
        model = self.datasourceArray[indexPath.row];
        identifierString = @"Cuetom";
    }else{
        model = self.rightDataArray[indexPath.row];
        identifierString = @"porfit";
    }
    BDGeneralCell *cell = [BDGeneralCell cellForTableView:self.tableView model:model indexPath:indexPath identifier:identifierString];
    
    cell.subviewBlock = ^(BDGeneralCell *generalCell) {
        if (currentSelect == 1) {
            generalCell.textLabel.font = [UIFont systemFontOfSize:14];
            generalCell.textLabel.textColor = [UIColor colorWithHexString:@"4c4c4c"];
            generalCell.textLabel.left = 20;
            generalCell.textLabel.numberOfLines = 0;
            generalCell.textLabel.textAlignment = NSTextAlignmentCenter;
            [generalCell.textLabel sizeToFit];
            generalCell.textLabel.top = (45 - generalCell.textLabel.height) / 2;
            
            generalCell.imageView.size = CGSizeMake(31, 31);
            generalCell.imageView.left = generalCell.textLabel.right + 20;
            generalCell.imageView.top = 7;
            generalCell.imageView.layer.cornerRadius = 31 / 2;
            generalCell.imageView.layer.masksToBounds = YES;
            
            generalCell.detailTextLabel.left = generalCell.imageView.right + 20;
            generalCell.detailTextLabel.font = [UIFont systemFontOfSize:14];
            generalCell.detailTextLabel.textColor = [UIColor colorWithHexString:@"4c4c4c"];
            [generalCell.detailTextLabel sizeToFit];
            generalCell.detailTextLabel.top = (45 - generalCell.detailTextLabel.height) / 2;
            
            generalCell.aLabel.left = kBDScreenWidth - 61;
            generalCell.aLabel.top = 12;
            generalCell.aLabel.size = CGSizeMake(21, 21);
            generalCell.aLabel.layer.masksToBounds = YES;
            generalCell.aLabel.layer.cornerRadius = 21 / 2;
            generalCell.aLabel.backgroundColor = [UIColor orangeColor];
            generalCell.aLabel.textColor = [UIColor whiteColor];
            generalCell.aLabel.textAlignment = NSTextAlignmentCenter;
            
            
            generalCell.customView.backgroundColor = [UIColor clearColor];
            
            UILabel *newNumberLabel = [generalCell.customView viewWithTag:5000];
            if (newNumberLabel == nil) {
                newNumberLabel = [[UILabel alloc] init];
                newNumberLabel.tag = 5000;
                newNumberLabel.font = [UIFont systemFontOfSize:14];
                newNumberLabel.numberOfLines = 0;
                newNumberLabel.text = ASLocalizedString(@"今日\n新增");
                [newNumberLabel sizeToFit];
                
                
                generalCell.customView.left = generalCell.aLabel.left - newNumberLabel.width - 20;
                generalCell.customView.top = (45 - newNumberLabel.height) / 2;
                generalCell.customView.size = CGSizeMake(newNumberLabel.width, newNumberLabel.height);
                newNumberLabel.left = 0;
                newNumberLabel.top = 0;
                
                [generalCell.customView addSubview:newNumberLabel];
            }
            
        }else{
            
            generalCell.imageView.left = 15;
            generalCell.imageView.top = 10;
            generalCell.imageView.size = CGSizeMake(40, 40);
            generalCell.layer.masksToBounds = YES;
            generalCell.layer.cornerRadius = 20;
            
            generalCell.textLabel.font = [UIFont systemFontOfSize:16];
            generalCell.textLabel.textColor = [UIColor colorWithHexString:@"1c1c1c"];
            generalCell.textLabel.left = generalCell.imageView.right + 15;
            generalCell.textLabel.top = 10;
            [generalCell.textLabel sizeToFit];
            
            generalCell.detailTextLabel.left = generalCell.textLabel.left;
            generalCell.detailTextLabel.top = generalCell.textLabel.bottom + 10;
            generalCell.detailTextLabel.font = [UIFont systemFontOfSize:13];
            generalCell.detailTextLabel.textColor = [UIColor colorWithHexString:@"767676"];
            [generalCell.detailTextLabel sizeToFit];
            
            generalCell.aLabel.font = [UIFont systemFontOfSize:18];
            generalCell.aLabel.textColor = [UIColor colorWithHexString:@"ff992b"];
            generalCell.aLabel.textAlignment = NSTextAlignmentCenter;
            [generalCell.aLabel sizeToFit];
            generalCell.aLabel.right = generalCell.width - 15;
            generalCell.aLabel.top = (60 - generalCell.aLabel.height) / 2;
        }
        
    };
    
    
    return cell;
}

-(CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (currentSelect == 1) {
        return 45;
    }else{
        return 60;
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (currentSelect == 1) {
        BDGeneralModel *model = _datasourceArray[indexPath.row];
        BDLevelViewController *levelVC = [[BDLevelViewController alloc] init];
        levelVC.generalModel = model;
        levelVC.levelString = _levelStringArray[indexPath.row];
        [self.navigationController pushViewController:levelVC animated:YES];
    }else{
        
    }
    
    
}

-(void)customerAction{
    
    self.rightView.hidden = YES;
    self.leftView.hidden = NO;
    _bgView.height = leftFloat;
    _detailsLabel.top = _bgView.bottom + 18 / 2;
    _detailsLabel.text = ASLocalizedString(@"客户明细");
    self.tableView.top = _detailsLabel.bottom + 9;
    self.tableView.height = kBDScreenHeight - self.tableView.top;
    self.tableView.scrollEnabled = NO;
    currentSelect = 1;
    
    [self.customerButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.profitButton setTitleColor:kNOValidColor forState:UIControlStateNormal];
    [UIView animateWithDuration:0.3 animations:^{
        self.lineView.left = (kBDScreenWidth - lineViewWidth) / 2;
    }];
    
    [self.tableView reloadData];
}

-(void)profitAction{
    
    currentSelect = 2;
    
    _bgView.height = rightFloat;
    self.rightView.height = rightFloat;
    _detailsLabel.top = _bgView.bottom + 18 / 2;
    _detailsLabel.text = ASLocalizedString(@"利润明细");
    self.tableView.top = _detailsLabel.bottom + 9;
    self.tableView.height = kBDScreenHeight - self.tableView.top;
    
    self.tableView.scrollEnabled = YES;
    
    self.rightView.hidden = NO;
    self.leftView.hidden = YES;
    
    [self.tableView reloadData];
    
    [self.customerButton setTitleColor:kNOValidColor forState:UIControlStateNormal];
    [self.profitButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [UIView animateWithDuration:0.3 animations:^{
        self.lineView.left = (kBDScreenWidth - lineViewWidth) / 2 + _customerButton.width + 20;
    }];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end

